<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
      
    >
      <el-form-item label="关键字" prop="keyword">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入名称/助记符"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>

    <el-row class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="助记码" align="center" prop="spell" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="单位" align="center" prop="permittedUnit" />
      <el-table-column label="状态" align="center" prop="num" />
      <el-table-column label="顺序" align="center" prop="displayOrder" />
      <el-table-column label="备注" align="center" prop="description" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)">
            编辑
          </el-button>
          <el-button size="mini" type="text" @click="handleDelete(scope.row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.skipCount"
      :limit.sync="queryParams.maxResultCount"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  addItem,
  updateItem,
  deleteItem,
  getItem,
  getList,
  importExcel,
} from "@/api/detail";
import EditForm from "./components/EditForm";
import TableForm from "./components/TableForm";
export default {
  name: "Detail",
  components: {
    EditForm,
    TableForm,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检查项目表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        skipCount: 0,
        maxResultCount: 10,
        FilterText: undefined,
        Sorting: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // tab切换
      activeName: "first",
      //
      detailItems: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    handleClick(tab, event) {
      // console.log(tab, event);
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      getList(this.queryParams).then((response) => {
        this.list = response.data.items;
        this.total = response.data.totalCount;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      // this.reset();
      this.$refs.editForm.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        spell: undefined,
        dataType: undefined,
        category: undefined,
        displayOrder: undefined,
        detailItems: [],
      };
      // this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.skipCount = 0;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.$router.push({
        path: "/detail/editDetailForm",
      });
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.$router.push({
        path: "/detail/editDetailForm",
        query: {
          detailId: row.id,
        },
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      console.log("ids", ids);
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return deleteItem(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "tijianyuyue/project/export",
        {
          ...this.queryParams,
        },
        `project_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

<style>
</style>
